package org.demo.patten.iterator;

/**
 * @author zhuj
 * @date 2025/3/29
 * @apiNote
 */
public class BookShelfIterator implements Iterator<Book> {
    private final BookShelf bookShelf;
    private int index;
    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }
    @Override
    public boolean hasNext() {
        return index < bookShelf.getLength();
    }
    @Override
    public Book next() {
        return bookShelf.getBookAt(index++);
    }
}
